'mojomodifications.monkey by Belimoth
Strict
Import mojo
'Import abutoolbox

#Rem
Put this in your header:
	Alias SetColor = mojomodifications.SetColor
	Alias Cls = mojomodifications.Cls
#End

Const COLOR_RED:Int = $FF0000
Const COLOR_GREEN:Int = $00FF00
Const COLOR_BLUE:Int = $0000FF

Const COLOR_YELLOW:Int = $FFFF00
Const COLOR_MAGENTA:Int = $FF00FF
Const COLOR_CYAN:Int = $00FFFF

Const COLOR_BLACK:Int = $000000
Const COLOR_WHITE:Int = $FFFFFF

Function SetColor:Void(r:Int, g:Int, b:Int)
	mojo.graphics.SetColor(r, g, b)
End

Function SetColor:Void(rgb:Int)
	Local color:Color = Color.Get(rgb)
	mojo.graphics.SetColor(color.r, color.g, color.b)
End

Function SetColor:Void(rgb:Int[])
	mojo.graphics.SetColor(rgb[0], rgb[1], rgb[2])
End

Function Cls:Void()
	mojo.graphics.Cls()
End

Function Cls:Void(r:Int, g:Int, b:Int)		'the parameters don't default to 0 like the mojo Cls
	mojo.graphics.Cls(r, g, b)
End

Function Cls:Void(rgb:Int)
	local color:Color = Color.Get(rgb)
	mojo.graphics.Cls(color.r, color.g, color.b)
End

Function Cls:Void(rgb:Int[])
	mojo.graphics.Cls(rgb[0], rgb[1], rgb[2])
End



Private

Class Color
	Global _cached := new IntMap<Color>
	
	Function Get:Color(rgb:Int)
		Local colorTemp:Color = _cached.Get(rgb)
		If colorTemp = Null
			colorTemp = New Color(rgb)
			_cached.Add(rgb, colorTemp)
		EndIf
		Return colorTemp
	End
	
	Field r:Int, g:Int, b:Int
	
	Method Rgb:Int() Property Return (r Shl 16) | (g Shl 8) | b End
	
	Method Rgb:Void(rgbNew:Int) Property
		Self.r = (rgbNew Shr 16) & $FF
		Self.g = (rgbNew Shr 8) & $FF
		Self.b = rgbNew & $FF
	End
	
	Method New(r:Int, g:Int, b:Int)
		Self.r = r
		Self.g = g
		Self.b = b
	End
	
	Method New(rgb:Int)
		Self.Rgb = rgb
	End
	
	'Method ToString:String()
	'	Return PaddedDecToHex(_r, 2) + PaddedDecToHex(_g, 2) + PaddedDecToHex(_b, 2)
	'End
End